home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
igo
/
src
/
kiffile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
4KB
|
186 lines
#define DEBUG 1
/*
TOWNS囲碁棋譜記録プログラム KIFFILE.C
1992/04/06 久保田俊也
*/
/*
機能
kiffileの読み込み
kiffileの書き込み
KIF_HEADERの読み込み
KIF_HEADERの書き込み
KIF_TEの読み込み(コメント付)
KIF_TEの書き込み(コメント付)
記憶域の割当機能まだ未完成
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winb.h>
#include <te.h>
#include <fntb.h>
#include <gui.h>
#include "ban19.h"
#include "kiffile.h"
#include "igo.h"
int te_no = 0;
void *alloc;
TE_ARG *te_p2;
KIF_HEADER_VER3 kiffile_header_ver3;
TE_ARG kiffile2[MAX_TE_NUMBER];
int kiffile_read(char fname[]);
int kiffile_write(char fname[]);
int kiftitle_read(KIF_TITLE *kiffile_title);
int kiftitle_write(KIF_TITLE kiffile_title);
int kifte_write(TE_ARG kiffile_te);
char *comment_read(int comment_no);
int kiffile_read(char fname[])
{
int i, c;
char comment[256];
FILE *fp;
if((fp=fopen(fname,"rb"))==NULL){
printf("read open error!\n");
return -1;
}
#if DEBUG
printf("kiffile read\n");
#endif
fread(&kiffile_header_ver3, sizeof(KIF_HEADER_VER3), 1, fp);
if(kiffile_header_ver3.file_id[0] == 'K' &&
kiffile_header_ver3.file_id[1] == 'I' &&
kiffile_header_ver3.file_id[2] == 'F' &&
kiffile_header_ver3.file_id[3] == '3' ){
alloc = TL_malloc(kiffile_header_ver3.te_number*sizeof(TE_ARG));
if(alloc == NULL){
printf("TL_malloc error!\n");
return -1;
}
fread(alloc, sizeof(TE_ARG), kiffile_header_ver3.te_number, fp);
i=0;
while((c = getc(fp))!=EOF){
if((comment[i] = (char)c) == '\0'){
comment_set(comment);
i=0;
}else{
i++;
}
}
}
if(fclose(fp)==EOF){
printf("read close error!\n");
return -1;
}
}
int kiftitle_read(KIF_TITLE *kiftitle)
{
kiftitle->te_number = kiffile_header_ver3.te_number;
kiftitle->play_start = kiffile_header_ver3.play_start;
kiftitle->play_end = kiffile_header_ver3.play_end;
kiftitle->handy = kiffile_header_ver3.handy;
kiftitle->komi_id = kiffile_header_ver3.komi_id;
kiftitle->komi_number = kiffile_header_ver3.komi_number;
kiftitle->hanmoku_id = kiffile_header_ver3.hanmoku_id;
strcpy(kiftitle->player_black, kiffile_header_ver3.player_black);
strcpy(kiftitle->player_white, kiffile_header_ver3.player_white);
strcpy(kiftitle->play_space, kiffile_header_ver3.play_space);
kiftitle->vicdef_id = kiffile_header_ver3.vicdef_id;
kiftitle->vicdef_number = kiffile_header_ver3.vicdef_number;
te_no = 0;
te_p2 = (TE_ARG *)alloc;
}
int kifte_read2(TE_ARG *kiffile_te)
{
*kiffile_te = *te_p2;
te_no++;
te_p2++;
if(te_no == kiffile_header_ver3.te_number){
TL_free(alloc);
return(1);
}
return(0);
}
int kiftitle_write(KIF_TITLE kiftitle)
{
kiffile_header_ver3.ver = kiftitle.ver;
kiffile_header_ver3.comment_lenth = kiftitle.comment_lenth;
kiffile_header_ver3.play_start = kiftitle.play_start;
kiffile_header_ver3.play_end = kiftitle.play_end;
kiffile_header_ver3.handy = kiftitle.handy;
kiffile_header_ver3.komi_id= kiftitle.komi_id;
kiffile_header_ver3.komi_number = kiftitle.komi_number;
kiffile_header_ver3.hanmoku_id = kiftitle.hanmoku_id;
strcpy(kiffile_header_ver3.player_black, kiftitle.player_black);
strcpy(kiffile_header_ver3.player_white, kiftitle.player_white);
strcpy(kiffile_header_ver3.play_space, kiftitle.play_space);
kiffile_header_ver3.vicdef_id = kiftitle.vicdef_id;
kiffile_header_ver3.vicdef_number = kiftitle.vicdef_number;
te_no = 0;
}
int kifte_write(TE_ARG kiffile_te2)
{
kiffile2[te_no] = kiffile_te2;
te_no++;
}
int kiffile_write( char fname[])
{
FILE *fp;
int c, i, j;
char *comment;
kiffile_header_ver3.file_id[0] = 'K';
kiffile_header_ver3.file_id[1] = 'I';
kiffile_header_ver3.file_id[2] = 'F';
kiffile_header_ver3.file_id[3] = '3';
kiffile_header_ver3.te_number = te_no;
if((fp=fopen(fname,"wb"))==NULL){
printf("write open error!\n");
return -1;
}
fwrite(&kiffile_header_ver3, sizeof(KIF_HEADER_VER3), 1, fp);
fwrite(&kiffile2[0], sizeof(TE_ARG), te_no, fp);
for(i=1;(comment=comment_read(i))!=NULL;i++){
j=0;
do{
c = (int)comment[j];
putc(c, fp);
j++;
}while((char)c != '\0');
}
fclose(fp);
return 0;
}